package net.huashitong.ssydt.provider.pk.service;


import net.huashitong.ssydt.base.dao.LongMapper;
import net.huashitong.ssydt.base.service.AbstractLongService;
import net.huashitong.ssydt.pk.entity.SsPkYmdxMyMedal;
import net.huashitong.ssydt.provider.pk.mapper.SsPkYmdxMyMedalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.12.20
 */
@Service
@Transactional
public class SsPkYmdxMyMedalServiceImpl extends AbstractLongService<SsPkYmdxMyMedal> implements SsPkYmdxMyMedalService {

    private SsPkYmdxMyMedalMapper mapper;

    @Autowired
    public SsPkYmdxMyMedalServiceImpl(SsPkYmdxMyMedalMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    protected LongMapper<SsPkYmdxMyMedal> getLongMapper() {
        return this.mapper;
    }

    @Override
    public SsPkYmdxMyMedal getByUserId(String userId) {
        return this.mapper.getByUserId(userId);
    }

    @Override
    public SsPkYmdxMyMedal getAutoCreateByUserId(String userId) {
        SsPkYmdxMyMedal ssPkYmdxMyMedal = this.getByUserId(userId);
        if (ssPkYmdxMyMedal == null) {
            ssPkYmdxMyMedal = new SsPkYmdxMyMedal();
            ssPkYmdxMyMedal.setUserId(userId);
            ssPkYmdxMyMedal.setGoldMedal(0);
            ssPkYmdxMyMedal.setSilverMedal(0);
            ssPkYmdxMyMedal.setBronzeMedal(0);
            this.mapper.insertSelective(ssPkYmdxMyMedal);
        }
        return ssPkYmdxMyMedal;
    }

    @Override
    public List<SsPkYmdxMyMedal> findCountMedalRank() {
        return this.mapper.findCountMedalRank();
    }

    @Override
    public List<SsPkYmdxMyMedal> findByGoldMedalNumberWithNotInTaskMedal(int number) {
        return this.mapper.findByGoldMedalNumberWithNotInTaskMedal(number);
    }
}
